package de.sas.za_expression.model;

import java.util.ArrayList;

public class Zelle {

	private ArrayList<Attribut> attribute;
	private String zellTyp;

	public Zelle(ArrayList<Attribut> attribut, String zellTyp) {
		if (attribut == null)
			this.setAttribute(new ArrayList<Attribut>());
		else
			this.setAttribute(attribut);
		this.zellTyp = zellTyp;
	}

	public Zelle(String zellTyp) {
		this.setAttribute(new ArrayList<Attribut>());
		this.zellTyp = zellTyp;
	}

	public void addAttribut(Attribut attr) {
		attribute.add(attr);
	}

	public ArrayList<Attribut> getAttribute() {
		return attribute;
	}

	public void setAttribute(ArrayList<Attribut> attribute) {
		this.attribute = attribute;
	}

	public Attribut getAttribut(String name) {
		for (Attribut tmpAttr : attribute) {
			if (tmpAttr.getName().equals(name))
				return tmpAttr;
		}

		return null;
	}

	public String getZellTyp() {
		return zellTyp;
	}

	@Override
	public String toString() {
		String returnString = "Zelle: Zelltyp=" + zellTyp + "[";
		for (Attribut tmpAttribut : attribute) {
			returnString += "[" + tmpAttribut + "], ";
		}

		int lastInd = returnString.lastIndexOf(",");
		returnString = returnString.substring(0, lastInd).concat("]");
		return returnString;
	}
}
